package com.example.demo.service;


import com.example.demo.dao.UserDao;
import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
  @Autowired
  private UserDao userDao;
  
  @Autowired
  private AccountService accountService;
  
  public User queryAndUpdateUser(String id) {
    User user = null;
    this.accountService.preCheckAccount(id);
    try {
      user = this.userDao.GetUserByID(1);
      System.out.println(user.toString());
    } catch (Exception e) {
      e.printStackTrace();
    } 
    System.out.println("end call.");
    return user;
  }
  
  public User queryAndUpdateUser_NotExist(String id) {
    User user = null;
    this.accountService.preCheckAccount(id);
    try {
      user = this.userDao.GetUserNotExistByID(1);
      System.out.println(user.toString());
    } catch (Exception e) {
      System.out.println("not exist db record. exception: " + e.getMessage());
    } 
    System.out.println("end call.");
    return user;
  }
  
  public void npeInvoke() throws Exception {
    String null_str = null;
    if (null_str.equals("this will throw NPE."))
      System.out.println("NPE"); 
  }
  
  public void exceptionFromAccountServiceInvoke() throws Exception {
    this.accountService.accountThrowException();
  }
}
